package org.iss.controller;

import com.google.gson.Gson;
import org.iss.model.ResponseMessage;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

@WebServlet(urlPatterns = "/sys/login")
public class LoginController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        Gson gson = new Gson();
        ResponseMessage responseMessage = new ResponseMessage();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        PrintWriter out = response.getWriter();

        if(username.equals("admin")&&password.equals("123456")){
            responseMessage.setFlag(true);
        }else {
            responseMessage.setFlag(false);
        }
        System.out.println("post:");
        out.println(gson.toJson(responseMessage));
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Gson gson = new Gson();
        ResponseMessage responseMessage = new ResponseMessage();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        PrintWriter out = response.getWriter();

        if(username.equals("admin")&&password.equals("123456")){
            responseMessage.setFlag(true);
        }else {
            responseMessage.setFlag(false);
        }
        System.out.println("get:");
        out.println(gson.toJson(responseMessage));
    }
}
